package zjh_20230405;

import java.time.LocalTime;
import java.util.Locale;
import java.util.concurrent.*;

public class CachePool {
    public static void main(String[] args) {
//        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0,Integer.MAX_VALUE,60L, TimeUnit.SECONDS,new SynchronousQueue<>());
        MyThreadFactory myThreadFactory = new MyThreadFactory();
        ExecutorService pool = Executors.newCachedThreadPool(myThreadFactory);
        System.out.println("当前时间：" + LocalTime.now());
        for (int i = 0; i < 10; i++) {
            int number = i;
            pool.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("当前时间：" + LocalTime.now() + ",线程"
                    + Thread.currentThread().getName() + ",序号" +number);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
        }
        pool.shutdown();
    }
}
class MyThreadFactory implements ThreadFactory{

    int i ;
    @Override
    public Thread newThread(Runnable r) {
        return new Thread(r,"自定义线程" + i++);
    }
}